<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
	<script type="text/javascript" src="js/jquery-easyui-1.4.1/jquery.min.js"></script>
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.1/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.1/themes/icon.css" />
	<script type="text/javascript" src="js/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="js/jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
//定义导出数据  提交的表单
var export_data=serializeForm($('#mysearch'));//导出全部时的查询条件
//格式化入职率
function rate(row){
if(row.viewerNu!='null'&&typeof(row.viewerNu)!='undefinded'){
	var rate = (parseInt)(row.entryNu)/(parseInt)(row.viewerNu)*100;
	return rate.toFixed(2)+"%";	
}else{
	return "";
}
}
//测试可以取到数据
function test(row){
	if(row.customer.organization.organizationName != null){
		return row.customer.organization.organizationName
	}
}
var export_data=serializeForm($('#mysearch'));
//js方法：序列化表单 			
function serializeForm(form) {
	var obj = {};
	$.each(form.serializeArray(), function(index) {
		if (obj[this['name']]) {
			obj[this['name']] = obj[this['name']] + ',' + this['value'];
		} else {
			obj[this['name']] = this['value'];
		}
	});
	return obj;
}
//招聘企业动态加载
function jilian_company (){
  var emp=$('#orgnizationid').combobox('getValue');
	$.post("<%=basePath%>dayrec/findqiye",{"orgnizationid":emp},
		function(data){
		var data = eval("(" + data + ")");
		$('#company_show').combobox({
			data:data,
			valueField:'id',
			textField:'enterpriseName',
			editable:false,
			panelHeight : 'auto'
		});
	});
}
/**
 * 导入的动作
 */
 
$(function(){
/* 	$('#download').click(function(){
		
		
	}); */
	
	$('#upload').click(function(){
		$('#importForm').form('submit',{
			url : "<%=basePath%>dayrec/imp",
			method : "post",
			cache : false,
			dataType : 'text',
			success : function(result){
                $('#import').dialog('close');
            	$('#importForm').form('reset');
            	$('#importForm').form('clear');
                $('#dayrec').datagrid('load', {});
				$('#dayrec').datagrid('unselectAll');
            	$.messager.alert('提示',result);				
			}
			
		})				
	});
	
/* 	$('#scan').click(function(){
		
	}); */
	
	$('#importCancel').click(function(){
		$('#importForm').form('clear');
		$('#import').dialog('close');
	});
	
})
$(function(){
	$('#searchbtn').click(function(){
		$('#dayrec').datagrid('load' ,serializeForm($('#mysearch')));
		$('#dayrec').datagrid('unselectAll');
	});	
	/**
	*提交表单方法
	**/
	$('#btnGo').click(function() {
		if ($('#form').form('validate')) {
			if (parseInt($('#entry').numberbox('getValue')) <= parseInt($(
					'#viewer').numberbox('getValue'))) {				
				$.ajax({
					type : 'post',
					url :$("#flag").val()=='add'?'<%=basePath%>dayrec/save':'<%=basePath%>dayrec/update',
					cache : false,
					data : $('#form').serialize(),
					dataType : 'text',
					success : function(result) {					
						$('#form').form('clear');
						$('#company').val('${user.organization.organizationName}');
						$("#flag").val("add");
						//2刷新datagrid 
						$('#dayrec').datagrid('load',export_data);
						$('#dayrec').datagrid('unselectAll');
						//3 温馨提示
						$.messager.show({
							title : '温馨提示',
							msg : '操作成功'
						});
					},
					error : function(result) {
						ajaxLoadEnd()
						$.messager.show({
							title : '温馨提示',
							msg : '操作失败'
						});
					}
				});
			} else {
				$.messager.show({
					title : '温馨提示!',
					msg : '入职人数大于面试人数,不能保存!'
				});
			}
		} else {
			$.messager.show({
				title : '温馨提示!',
				msg : '信息不完整或格式不正确,不能保存!'
			});
		}
	});
	$('#btnSuc').click(function() {
		//验证数据是否通过验证
				if ($('#form').form('validate')) {
					if (parseInt($('#entry').numberbox('getValue')) <= parseInt($(
							'#viewer').numberbox('getValue'))) {
						
						$.ajax({
							type : 'post',
							url : $("#flag").val()=='add'?'<%=basePath%>dayrec/save':'<%=basePath%>dayrec/update',
							cache : false,
							data : $('#form').serialize(),
							dataType : 'text',
							success : function(result) {
								
								//1 关闭窗口
								$('#rec').dialog('close');
								//2刷新datagrid 
								$('#dayrec').datagrid('reload');
								//3清空idField   
								$('#dayrec').datagrid('unselectAll');
								//3 温馨提示
								$.messager.show({
									title : '温馨提示',
									msg : '操作成功'
								});
							},
							error : function(result) {
								ajaxLoadEnd()
								$.messager.show({
									title : '提示',
									msg : '操作失败'
								});
							}
						});
					} else {
						$.messager.show({
							title : '温馨提示!',
							msg : '入职人数大于面试人数,不能保存!'
						});
					}
				} else {
					$.messager.show({
						title : '温馨提示!',
						msg : '信息不完整或格式不正确,不能保存!'
					});
				}
			});
		

	$('#btnCancel').click(function(){
		//取消按钮 对话框关闭
		$('#rec').dialog('close');
		
	})
			//分公司下拉表
		$.post("<%=basePath%>dayrec/findfen",null,function(data){
			var data = eval("(" + data + ")");
			$('#orgnizationid').combobox({
				data:data,
				valueField:'id',
				textField:'organizationName',
				editable:false,
				panelHeight : 'auto'
			});
		});
	//招聘企业()
	$.post("<%=basePath%>dayrec/findqiye",function(data){
		var data2 = eval("(" + data + ")");
		$('#company_show').combobox({
			data:data2,
			valueField:'id',
			textField:'enterpriseName',
			editable:false,
			panelHeight : 'auto'
		});
	});
	$('#clearbtn').click(function() {
		$('#mysearch').form('clear');
		$.post("<%=basePath%>dayrec/findqiye",function(data){
			$('#dayrec').datagrid('load', {});
			var data = eval("(" + data + ")");
			$('#company_show').combobox({
				data:data,
				valueField:'id',
				textField:'enterpriseName',
				editable:false,
				panelHeight : 'auto'
			});
		});
		$('#dayrec').datagrid('unselectAll');
	});
	$.post("<%=basePath%>dayrec/findqiye",{flag:"add"},function(data){
		var data3 = eval("(" + data + ")");
		$('#enterpriseName').combobox({
			data:data3,
			valueField:'id',
			textField:'enterpriseName',
			editable:false,
			required:true,
			missingMessage:'请选择招聘企业',
			panelHeight : 'auto'
		});
	});
	var flag;
	/**
	*初始化table
	*/
	$('#dayrec').datagrid({
		idField:'id',
		stripted:true,
		loadMag:'数据正在加载，请稍后。。。',
		rownumbers:true,		
		url:'<%=basePath%>dayrec/find',
		fit:true,
		pagination : true,
		pageSize : 5,
		pageList : [ 5, 10, 15, 20, 50 ],
		frozenColumns : [ [ //冻结列特性 ,不要与fitColumns 特性一起使用 
		        			{
		        				field : 'ck',
		        				width : 50,
		        				checkbox : true
		        			}, {
		        				field : 'date',
		        				title : '日期',
		        				width : 100
		        			}, ] ],
		        			columns : [ [ {
		        				field : 'organizationName',
		        				title : '公司名',
		        				width : 100,
		        		 		formatter:function(value,row,index){
		        					return row.customer.organization.organizationName;
		        				}  
		        			},  
		        			 {
		        				field : 'enterpriseName',
		        				title : '招聘企业',
		        				width : 200,
		        		 		formatter:function(value,row,index){
		        					return row.customer.enterpriseName;
		        				}  
		        			}  ,{
		        				field : 'viewerNu',
		        				title : '面试人数',
		        				width : 60
		        			}, {
		        				field : 'entryNu',
		        				title : '入职人数',
		        				width : 60
		        			}, {
		        				field : 'rate',
		        				title : '入职率(%)',
		        				width : 90,
		        				formatter : function(value, row, index) {
		        					return rate(row);
		        				}
		        			}, {
		        				field : 'remarks',
		        				title : '备注',
		        				width : 200
		        			} ] ],
		         toolbar:[
		         {
						id:'btn_add',
						text : '新增日清',
						iconCls : 'icon-add',
						handler : function() {
							$('#rec').dialog({
								title : '添加日清'
							});
							$('#form').form('clear');
							$('#form').get(0).reset();
							$('#company').val('${user.organization.organizationName}');
							$("#flag").val("add");
							$('#btnGo').show();
							$('#rec').dialog('open');
							}
						},
						{
							id:'btn_update',
							text : '修改日清',
							iconCls : 'icon-edit',
							handler : function() {								
								var arr = $('#dayrec').datagrid(
										'getSelections');
								if (arr.length != 1) {
									$.messager.show({
										title : '温馨提示!',
										msg : '请最多选择一条记录进行修改。',
									});
									return;
								}
								else{
				        			$('#rec').dialog({
				        				title:'修改日清',			        							        				
				        			});
									$('#form').form('clear');
									$('#form').get(0).reset(); //清空表单数据 
									$.post("<%=basePath%>dayrec/findByid",
												{
													"id" : arr[0].id
												},
												function(val) {
													var data = eval("("+ val+ ")")[0];
													$('#form').form('load',
															{ //调用load方法把所选中的数据load到表单中,非常方便
																id : data.id,
																remarks : data.remarks,
																viewerNu : data.viewerNu,
																entryNu:data.entryNu
															});
													$("#flag").val("update")
													$("#enterpriseName").combobox('select',data.customer.id);
													$('#date').datebox('setValue',data.date);
													$('#company').val('data.customer.organization.organizationName');
													$('#btnGo').hide();
													$('#rec').dialog('open'); //打开窗口
												});
											}
										}
									},
			        	 		        	 
									{
										id:'btn_delete',
										text : '删除日清记录',
										iconCls : 'icon-remove',
										handler : function() {
											var arr = $('#dayrec').datagrid(
													'getSelections');
											if (arr.length == 0) {
												$.messager.show({
													title : '温馨提示!',
													msg : '至少选择一行记录进行删除!'
												});
											} else {
												var info = "确认要删除？";
												var ids = '';
												for (var i = 0; i < arr.length; i++) {
													ids += arr[i].id + ',';
												}
												ids = ids.substring(0,ids.length - 1);
												$.messager.confirm('温馨提示',info,function(r) {
													if (r) {
														$.post('<%=basePath%>dayrec/del',
																{
																	ids : ids
																},
																function(result) {
																	//1 刷新数据表格 
																	$('#dayrec').datagrid('reload');
																	$('#dayrec').datagrid('unselectAll');
																	//3 给温馨提示 
																	$.messager.show({
																				title : '温馨提示!',
																				msg : '操作成功!'
																			});
																});
																	} else {
																		return;
																	}
													});
											}
										}
									},
									{
										text : '查询日清',
										iconCls : 'icon-search',
										handler : function() {
											$('#lay').layout('collapse', 'north');
										}
									},
									{
										text : '日清导入',
										iconCls : 'icon-print',
										handler : function(){
											$('#import').dialog('open');
										}
										
									},
								
									{
										id:'btn_export',
										text : '导出所选行',
										iconCls : 'icon-print',
										handler : function() {
											var arr = $('#dayrec').datagrid(
													'getSelections');
											if (arr.length <= 0) {
												$.messager.show({
													title : '温馨提示!',
													msg : '至少选择一行记录进行导出!'
												});
											} else {
												$.messager.confirm('温馨提示','确认导出?',function(r) {
													if (r) {
														var ids = '';
														for (var i = 0; i < arr.length; i++) {
															ids += arr[i].id+ ',';
														}
														ids = ids.substring(0,ids.length - 1);
														$('#downform').form('submit', {
													        url : "<%=basePath%>dayrec/exportSelected",
													        method : "post",
													        onSubmit: function(param){
												                param.ids = ids;
												            },
												            error : function() {
												                $.messager.alert('温馨提示', '导出失败');
												            },												            												            												            
												            });
														$('#dayrec').datagrid('unselectAll');
													} else {
														return;
													}
													
												});
											}
										}
									},
									{id:'btn_export',
										text : '导出查询结果',
										iconCls : 'icon-print',
										handler : function() {
												$.messager.confirm('温馨提示','确认导出?',function(r) {
													if (r) {
														export_data=serializeForm($('#mysearch'));
														$('#downform').form('submit', {
													        url : "<%=basePath%>dayrec/export",
													        method : "post",
													        onSubmit: function(param){
												                param.search =export_data;
												                param.date_start=export_data.date_start;
												                param.date_end=export_data.date_end;
												            },
												            error : function() {
												                $.messager.alert('温馨提示', '导出失败');
												            }
													    });
													} else {
														return;
													}
												});
										}
									}]
	})		
})

</script>
</head>
<body>
	<div id="lay" class="easyui-layout" style="width: 100%; height: 100%">
		<div  region="north" title:'招聘日清查询' split="true" style="height:100px;">
			<form id="mysearch" method="post">
				<table  style="margin-bottom: -15px">
					<tr>
						<td>招聘日清日期:</td><td><input type="text" name="date_start"
							class="easyui-datebox" data-options="editable:false"></td>
							<td>到</td><td><input type="text" name="date_end"
							class="easyui-datebox" data-options="editable:false"></td>
							<td>公司名：</td><td><input id="orgnizationid" class="easyui-combobox"
							name="orgid" data-options="onSelect:function(){jilian_company();}"/>
						</td></tr><tr>
						<td>招聘企业：</td><td><input class="easyui-combobox" name="customer.id" id="company_show"></td>
						<td align="center" colspan="4"><a id="searchbtn"
							class="easyui-linkbutton">查询</a> &nbsp;&nbsp;&nbsp; <a
							id="clearbtn" class="easyui-linkbutton">清空</a></td>
					</tr>
				</table>
			</form>

		</div>
		<div region="center">
			<table id="dayrec"></table>		
			<form id="downform"  method="post">
				
			</form>	
		</div>
		</div>		
		<!-- 日清添加 -->
		<div id="rec" title="详情添加" modal=true draggable=true align="center"
			class="easyui-dialog" closed=true style="width: 260px">
			<form id="form">
				<input type="hidden" id="id" name="id" >
				<input type="hidden" id="flag" name="flag" >
				<table>
					<tr>
						<td>日期:</td> 
						<td><input  id="date" name="date" class="easyui-datebox" data-options="editable:false"
							required="true" missingMessage="请选择日清日期"></td>
					</tr>
					<tr>
						<td>公司名:</td>
						<td><input type="text"  id="company" readonly="readonly"  ></td>
					</tr>
					<tr>
						<td>招聘企业:</td>
						<td><input id="enterpriseName" class="easyui-combobox"
							name="customer.id"></td>
					</tr>
					<tr>
						<td>面试人数：</td>
						<td><input type="text" id="viewer" name="viewerNu"
							class="easyui-numberbox" data-options="min:0,max:99999" required="true"
							missingMessage="请填写面试人数"></input></td>
					</tr>
					<tr>
						<td>入职人数：</td>
						<td><input type="text" id="entry" name="entryNu"
							class="easyui-numberbox"  data-options="min:0,max:99999" required="true"
							missingMessage="请填写入职人数"></td>
					</tr>
					<tr>
						<td>备注:</td>
						<td><textarea name="remarks" cols="20" rows="2" style="resize:none;" class="easyui-validatebox" data-options="validType:['length[0,200]']" id="remark"></textarea></td>
					</tr>
					<tr >
						<td align="right" colspan="2"><a id="btnGo" class="easyui-linkbutton">继续添加</a>&nbsp;&nbsp;&nbsp;
						<a id="btnSuc" class="easyui-linkbutton">完成</a>&nbsp;&nbsp;&nbsp;
						<a id="btnCancel" class="easyui-linkbutton">取消</a>&nbsp;&nbsp;</td>
					</tr>
				</table>
			</form>
		</div>
		<div id = "import" title="员工信息导入" modal=true draggable=true align="center" class="easyui-dialog" closed=true style="width: 400px">
		<form id="importForm" method="post" enctype="multipart/form-data">
		<table id="importTable" align="center">
		<tr> 
		<td align="center" colspan="2">
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;上传：<input id = "myFile" name="myFile" type="file"></input>
		</td>
		
		 </tr>
		
				
		<tr>
			<td align ="center" colspan="2"><a id="download" href="<%=basePath %>import_template/template-dayrecruit.xls" class="easyui-linkbutton" >模板下载</a>&nbsp;&nbsp;&nbsp;
						<a id="upload" class="easyui-linkbutton">上传</a>&nbsp;&nbsp;&nbsp;
						<a id="importCancel" class="easyui-linkbutton">取消</a>&nbsp;&nbsp;</td>		
		</tr>
		</table>
		</form>
		</div>
</body>
</html>